var forumNameExistFlag = false;
var trNodeTag;

function bindForumStatus() {
	var status = $("#hiddenTopicActiveQuery").val();
	$("#topicActiveQuery").val(status);
}

function searchTopic() {
	document.topicListForm.action = "/EKMS-web/forum/visitForum/showForumDetails.do?action=listTopic";
	document.topicListForm.submit();
}

function resetForumSearch() {
	$("#forumNameQuery").attr("value", "");
	$("#forumActiveQuery").val("");
}

function sortTopic(eventSrc) {
	// Set Sort Type according Link title
	var type = eventSrc.title;
	$("#sortType").val(type);
	// Set Sort Order
	var order = $("#sortOrder").val();
	if (order == "asce") {
		sortOrder = "desc";
		$("#sortOrder").val("desc");
	} else {
		sortOrder = "asce";
		$("#sortOrder").val("asce");
	}
	document.topicListForm.action = "/EKMS-web/forum/visitForum/showForumDetails.do?action=listTopic";
	document.topicListForm.submit();

}

function goToFirstPage() {
	$("input[name='targetPage']").val(1);
	goToPage();
}

function goToPreviousPage() {
	var now = $("input[name='nowPage']").val();
	var total = $("input[name='totalPage']").val();
	if (parseInt(now) - 1 >= 1) {
		document.topicListForm.action = "/EKMS-web/forum/visitForum/showForumDetails.do?action=goToPreviousPage";
		document.topicListForm.submit();
	} else {
		alert("This is the first page!");
	}
}

function goToPreviousPage() {
	var now = $("input[name='nowPage']").val();
	var total = $("input[name='totalPage']").val();
	if (parseInt(now) - 1 >= 1) {
		document.topicListForm.action = "/EKMS-web/forum/visitForum/showForumDetails.do?action=goToPreviousPage";
		document.topicListForm.submit();
	} else {
		alert("This is the first page!");
	}
}

function goToNextPage() {
	var now = $("input[name='nowPage']").val();
	var total = $("input[name='totalPage']").val();
	if (parseInt(now) + 1 <= total) {
		document.topicListForm.action = "/EKMS-web/forum/visitForum/showForumDetails.do?action=goToNextPage";
		document.topicListForm.submit();
	} else {
		alert("This is the last page!");
	}
}

function goToLastPage() {
	var total = $("input[name='totalPage']").val();
	$("input[name='targetPage']").val(total);
	goToPage();
}

function goToPage() {
	var target = $("input[name='targetPage']").val();
	var total = $("input[name='totalPage']").val();
	if (typeof (target) != NaN && parseInt(target) > 0
			&& parseInt(target) <= parseInt(total)) {
		document.topicListForm.action = "/EKMS-web/forum/visitForum/showForumDetails.do?action=goToTargetPage";
		document.topicListForm.submit();
	} else {
		alert("The page number must be a number and between 0 and " + total
				+ "!");
	}
}

function check(field, limit) {
	if (field.value.length >= limit) {
		field.value = field.value.substr(0, limit - 1);
		field.focus();
	}
}

var message;

// Post data to URL using method
function post_to_url(path, params, method) {

	// If not defined, use post as default
	method = method || "post";

	var form = document.createElement("form");
	form.setAttribute("method", method);
	form.setAttribute("action", path);

	for ( var key in params) {
		var hiddenField = document.createElement("input");
		hiddenField.setAttribute("type", "hidden");
		hiddenField.setAttribute("name", key);
		hiddenField.setAttribute("value", params[key]);
		form.appendChild(hiddenField);
	}

	document.body.appendChild(form);
	form.submit();
}
function showTopicDetail(a) {
	var id = parseInt(a.name);
	post_to_url('/EKMS-web/forum/visitForum/showTopicDetails.do?action=listReply', {
		'topicId' : id
	}, 'post');
}

function newTopic(a){
	document.create_topic_form.submit();

}